//
//  AkuNetWorkTool.m
//  AkuCareLink
//
//  Created by 阿酷 on 16/7/5.
//  Copyright © 2016年 AkuApp. All rights reserved.
//

#import "AkuNetWorkTool.h"

@implementation AkuNetWorkTool


+ (instancetype)shareManager {
    
    static AkuNetWorkTool *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
        
        instance = [[AkuNetWorkTool alloc] initWithSessionConfiguration:config];
        
        // 可接受格式
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
        
        // 请求格式 (默认 二进制)
        instance.requestSerializer = [AFJSONRequestSerializer serializer];
        
        // 最大超时时间
        instance.requestSerializer.timeoutInterval = 10.0;
        
    });
    return instance;
}

+ (void)GET_RequestWithURLString:(NSString *)url params:(NSDictionary *)dic successBlock:(SuccessCompletedBlock)successBlk errorBlock:(FailureCompletedBlock)errorBlk{
    
    [[AkuNetWorkTool shareManager] GET:url parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlk(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        errorBlk(error);
    }];

}

+ (void)POST_RequestWithURLString:(NSString *)url params:(NSDictionary *)dic successBlock:(SuccessCompletedBlock)successBlk errorBlock:(FailureCompletedBlock)errorBlk{

    [[AkuNetWorkTool shareManager] POST:url parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlk(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        errorBlk(error);
    }];
    
}

@end
